home *** CD-ROM | disk | FTP | other *** search
- Path: news.mcs.net!mdp
- From: mdp@mika-sys.com (Michael D. Perry)
- Newsgroups: comp.lang.c
- Subject: Save My Sanity, Please Help; was Bitwise Operators, Help with please!
- Date: Mon, 12 Feb 96 01:03:04 GMT
- Organization: MIKA Systems
- Message-ID: <4fm3k8$nck_001@pr.mcs.net>
- References: <4fjaju$i1o_001@pr.mcs.net>
- NNTP-Posting-Host: mdp.pr.mcs.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- I posted the below quoted post last night and have continued to
- try and solve this problem with no luck - this is driving me nuts
- that I cannot figure this out. Please help.
-
- Thanks in advance.
-
- Mike
-
- In article <4fjaju$i1o_001@pr.mcs.net>,
- mdp@mika-sys.com (Michael D. Perry) wrote:
- >Hello All;
- >
- >I am trying to teach myself 'C' programming from a book which
- >perhaps is not explaining the Bitwise Operators as well as I
- >would desire in order to understand them.
- >
- >After going through a few examples the book is having me write a
- >program that will pack som data and then unpak using bitwise
- >operators. I have the packing down OK and can print the bits
- but
- >am just not getting the Unpacking.
- >
- >What I want to do is to unpack each 'field' of a type short with
- >the data as follows:
- >
- >Identification Job Type Gender
- >============== ======== ======
- >bbbbbbbbb bbbbbb b
- >
- >and then be able to read the returned bits and conver them back
- >to their original 'readable' form.
- >
- >Can someone help me with some code so I can at least see how
- this
- >would be done and maybe understand it then?
- >
- >What I have so far is listed below and thanks for your
- >assistance in advance.
- >
- >Mike
- >
- >
- >= = = = = = = = = =
- >
- >#include <stdio.h>
- >#include <limits.h>
- >
- >short create_employee_data(int, int, char);
- >void bit_print(int);
- >short unpak(int, int);
- >
- >main()
- >{
- > int id_no = 255;
- > int job_type = 63;
- > char gender = 'F';
- > short employee;
- >
- > employee = create_employee_data(id_no,
- > job_type,
- > gender);
- > bit_print(employee);
-
- -------------------------------------------------------------------
- Michael D. Perry | FIRST RULE OF INTELLIGENT TINKERING:
- MIKA Systems | Save all the parts.
- Glen Ellyn, Illinois | SATTINGER'S LAW:
- mdp@mika-sys.com | It works better if you plug it in.
- -------------------------------------------------------------------
-